home *** CD-ROM | disk | FTP | other *** search
- /*//////////////////////////////////////////////////////////////////////
- filename: showlogs.js
- copyright(c): Tiny Software corp 2002, 2003 (http://www.tinysoftware.com)
- author: Jozef Palocko (jpalocko@tinysoftware.com)
- product: Tiny Personal Firewall 5.x
- description: implemetation of Log analyzer
- ///////////////////////////////////////////////////////////////////////*/
-
- //filter XML file content
- var FILTER_XML = '<?xml version="1.0" encoding="UTF-8"?><filter><module/><string/><ar/><app/><fnc/><protocol/><ip/>\
- <direction/><locport/><remport/><user/><domain/><datetime/><cnt/><sort/></filter>';
- var g_lastShownFile = new String();
- var LT_PATH = 1,
- LT_CHECKSUM_AND_PATH = 3;
-
- var s_iDisplayType = 0,
- s_arrStyleSheets = new Array("Event_compact.xsl", "Event_detail.xsl"),
- s_arrStyleSheets_ie5 = new Array("Event_compact.xsl", "Event_ie5_detail.xsl");
-
- //main funtion
- function Main()
- {
- var srcDest = new ActiveXObject("Msxml2.DOMDocument.4.0");
- var nodeRoot = srcDest.selectSingleNode("/");
- var nodeTop = srcDest.createElement("filelist");
- nodeRoot.appendChild(nodeTop);
- srcDest.async=false;
-
- if (!CheckDates())
- return;
-
- //creates or replaces filter.xml
- InitFilter();
-
- var ret ="" ;
- idNavBar.innerHTML ="";
-
- //get dates from form
- var strDate = new String (dateFrom.value);
- dFrom = new Date( Date.parse (strDate.replace ('-',"/")));
- strDate = new String (dateTo.value);
- dTo = new Date(Date.parse (strDate.replace ('-',"/")));
-
- var firstFile ="";
- var strDelimiter = "";
- var strNavBar = "";
-
- var strOneDay ="";
- var strDate ="";
- var fileDayCount = 0;
- var arrLogsByDays = new Array;
-
- arrLogFilesVB = window.external.GetLogFiles();
- if(arrLogFilesVB!=null)
- {
- arrLogFiles = arrLogFilesVB.toArray();
- for (i = 0; i < arrLogFiles.length; i++)
- {
- dateFile = GetDateOfFile(arrLogFiles[i]);
- if (dateFile >= dFrom && dateFile <= dTo)
- {
- //user
- Node = srcDest.createElement("file");
- Node.text = arrLogFiles[i];
- nodeTop.appendChild(Node);
-
- if (firstFile == "")
- firstFile = GetLogDir() + arrLogFiles[i];
- var strDate = (dateFile.getMonth()+1) +"."+dateFile.getDate()+"."+dateFile.getYear();
- strDayLog = arrLogsByDays[strDate];
- if ( strDayLog == null) //create full day string
- {
- fileDayCount =1;
- strlink = GetHtmlLink(GetLogDir() + arrLogFiles[i], fileDayCount);
- arrLogsByDays[strDate] = strDate +" "+strlink+" ";
- }
- else //add only new link
- {
- fileDayCount ++;
- strlink = ", "+GetHtmlLink(GetLogDir() + arrLogFiles[i], fileDayCount);
- strDayLog += strlink;
- arrLogsByDays[strDate] = strDayLog;
- }
- }
- }
- }
-
- i=0;
- for (logfile in arrLogsByDays)
- {
- strDelimiter = i==0? "": " - ";
- strNavBar += strDelimiter + arrLogsByDays[logfile] ;
- i++;
- }
-
- window.external.SaveTPFFile(srcDest.xml, "loganalyzer/files.xml");
-
- idNavBar.innerHTML = strNavBar;
-
- //set initial file
- if ( firstFile!= "")
- {
- // document.all.idResultFrame.src = GetLogDir()+ arrLogFiles[0];
- ShowLog(firstFile);
- }
-
- OnResize();
- }
-
- //set url to result frame
- function ShowLog(file)
- {
- document.frames("idResultFrame").document.body.innerHTML = '<DIV class="clsEvent">Please wait while log is being prepared...</DIV>';
- g_lastShownFile = file;
- setTimeout('ShowLogFinish();', 1);
- // if (IsIE6())
- // {
- // document.all.idResultFrame.src = file;
- // } else
- // document.all.idResult.innerHTML = TransformXML( file, "log.xsl");
- }
-
- function ShowLogFinish(file)
- {
- var strResult;
- if (IsIE6())
- strResult = TransformXML( g_lastShownFile, s_arrStyleSheets[s_iDisplayType]);
- else
- strResult = TransformXML( g_lastShownFile, s_arrStyleSheets_ie5[s_iDisplayType]);
- //strResult = TransformXML( g_lastShownFile, "log-ie5.xsl");
- document.frames("idResultFrame").document.body.innerHTML = strResult;
- }
- //returns html code for link
- function GetHtmlLink(strTarget, strText)
- {
- str = "<a href=# Name=\""+strTarget+"\" OnClick=\"ShowLog(this.name)\"><b>"+strText+"</b></a>";
- return str;
- }
- //return date object from given log filename
- function GetDateOfFile(strFile)
- {
- arrDate = strFile.split("_");
- strDate = arrDate[0];
- strYear = "20" + strDate.substr(0,2);
- strMonth = strDate.substr(2,2);
- strDay = strDate.substr(4,2);
- dateFile = new Date(Date.parse(strYear + "/" +strMonth +"/"+strDay));
- return dateFile;
- }
- //check of existance of file - loads xml file, if file not found return false, else returns true
- function CheckFile(filePath)
- {
- var bExist = false;
-
- var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.4.0");
- xmlDoc.async = false;
- xmlDoc.validateOnParse = false;
- if (xmlDoc.load (filePath))
- {
- xmlDoc = null;
- return true;
- }
- else
- {
- xmlDoc = null;
- return false;
- }
- }
-
- //check correct date format
- function CheckDates()
- {
- var ERR_DATE_FORMAT = "Incorrect date format. Correct format is YYYY/MM/DD.";
- var ERR_DATE_RANGE = "Incorrect date range.";
- var strDate = new String (dateFrom.value);
- dFrom = Date.parse (strDate.replace ('-',"/"));
-
-
- strDate = new String (dateTo.value);
- dTo = Date.parse (strDate.replace ('-',"/"));
-
-
- if (!dFrom || !dTo)
- {
- alert(ERR_DATE_FORMAT);
- return false;
- }
- if (dFrom>dTo)
- {
- alert(ERR_DATE_RANGE);
- return false;
- }
- return true;
- }
-
- //returns log filename generated from given date and order: eg. 030722_001.xml
- function GetFileName(d, i)
- {
- var strFile = new String;
- var tmp = new String;
-
- tmp += d.getYear();
- strFile += tmp.substr(2,2);
-
- tmp=""; tmp += d.getMonth() + 1;
- if (tmp.length ==1)
- tmp = "0" +tmp;
- strFile +=tmp;
-
- tmp="";tmp += d.getDate();
- if (tmp.length ==1)
- tmp = "0" +tmp;
- strFile += tmp;
-
- var index;
- if (i<10)
- index = "00"+i;
- else if(i<100)
- index = "0"+i;
- else
- index = i;
-
- strFile += "_"+ index + ".xml";
- return strFile;
- }
-
-
-
- //returns path of log dir where generated log files are stored
- function GetLogDir()
- {
- var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
- xmlDoc.async = false;
- xmlDoc.resolveExternals = false;
- xmlDoc.load("logcfg.xml");
- currNode = xmlDoc.selectSingleNode("//Logdir");
- strDir = currNode.text;
- var ch = strDir.charAt(strDir.length-1)
- if (ch !='\\')
- strDir+="\\";
- return strDir;
- }
-
- //profiler function
- function getElapsedTime(date)
- {
- d = new Date(); //Create Date object.
- r = d.getTime() - date.getTime(); //Get current time.
- r = r/1000;
- return(r); //Return difference.
- }
-
- //initialize date form fields
- function InitFields ()
- {
- var d = new Date();
- var strDate = new String;
- var tmp = new String;
-
- tmp += d.getYear();
- strDate += tmp + "/";
-
- tmp=""; tmp += d.getMonth() + 1;
- if (tmp.length ==1)
- tmp = "0" +tmp;
- strDate +=tmp + "/";
-
- tmp="";tmp += d.getDate();
- if (tmp.length ==1)
- tmp = "0" +tmp;
- strDate += tmp;
-
- dateFrom.value = strDate;
- dateTo.value = strDate;
-
- idDivSelectApp.innerHTML = GetComboApps();
-
- var arrOptions = idModule.options, arrSortOptions = idSort.options, i = 0;
- var strPropModule = "";
- strPropModule = window.external.StringProperty("logs-module");
- if (strPropModule != "")
- {
- for (i = 0; i < arrOptions.length; i++)
- {
- if (arrOptions[i].value == strPropModule)
- {
- idModule.selectedIndex = i;
- break;
- }
- }
- document.all.idFilter.className = "clsShow";
- }
- var strPropSort = "";
- strPropSort = window.external.StringProperty("logs-sort");
- if (strPropSort != "")
- {
- for (i = 0; i < arrSortOptions.length; i++)
- {
- if (arrSortOptions[i].value == strPropSort)
- {
- idSort.selectedIndex = i;
- break;
- }
- }
- document.all.idFilter.className = "clsShow";
- }
- radio_display[s_iDisplayType].checked = 1;
- }
-
- //loads and saves filter xml file
- function InitFilter()
- {
- var srcDest = new ActiveXObject("Msxml2.DOMDocument.4.0");
- srcDest.async=false;
- srcDest.loadXML(FILTER_XML);
-
- //user
- var strMain = window.external.LoggedUser, strUser, strDomain;
- var arrComp = strMain.split("@");
- if (arrComp.length > 1)
- {
- strUser = arrComp[0];
- strDomain = arrComp[1];
- }
- else if (arrComp.length == 1)
- {
- strUser = arrComp[0];
- strDomain = "";
- }
- else
- {
- strUser = "";
- strDomain = "";
- }
- Node = srcDest.selectSingleNode("//user");
- Node.text = strUser
- //domain
- Node = srcDest.selectSingleNode("//domain");
- Node.text = strDomain;
-
- // no. of events
- Node = srcDest.selectSingleNode("//cnt");
- Node.text = select_noevents.options[select_noevents.selectedIndex].value;
-
- if( document.all.idFilter.className == "clsShow" ) // BUILD FILTER CONTENT
- {
- //set module filter
- Node = srcDest.selectSingleNode("//module");
- Node.text = idModule.options[idModule.selectedIndex].value;
- //application
- Node = srcDest.selectSingleNode("//app");
- Node.text = idApp.value;
- //acces result
- Node = srcDest.selectSingleNode("//ar");
- Node.text = idAr.options[idAr.selectedIndex].value;
- //sort order
- Node = srcDest.selectSingleNode("//sort");
- Node.text = idSort.options[idSort.selectedIndex].value;
-
- switch(idModule.options[idModule.selectedIndex].value)
- {
- case "1": //sandbox
- case "16": //IDS
- Node = srcDest.selectSingleNode("//string");
- Node.text = idObject.value;
- break;
- case "2": //firewall
- //protocol
- Node = srcDest.selectSingleNode("//protocol");
- Node.text = idProtocol.options[idProtocol.selectedIndex].value;
- //ip Adress
- Node = srcDest.selectSingleNode("//ip");
- Node.text = idIP.value;
- //direction
- Node = srcDest.selectSingleNode("//direction");
- Node.text = idDirection.options[idDirection.selectedIndex].value;
- //loc port
- Node = srcDest.selectSingleNode("//locport");
- Node.text = idLocPort.value;
- //rem port
- Node = srcDest.selectSingleNode("//remport");
- Node.text = idRemPort.value;
- break;
-
- default: //All
- break;
- }
- }
- //save filter file
- window.external.SaveFilterFile( srcDest.xml);
-
- return srcDest;
- }
- //return true if is IE version 6 and later, else return false
- function IsIE6()
- {
- iVersion = parseInt(navigator.appVersion);
- if (-1 != navigator.appVersion.search("MSIE 6"))
- return true;
- else
- return false;
- }
- //trnsforms XMl file with xsl template
- function TransformXML(xmlDoc, xslPath )
- {
- var srcTree = new ActiveXObject("Msxml2.DOMDocument.4.0");
- // this line caused the currently generated log to not open
- // srcTree.async=false;
- srcTree.load(xmlDoc);
-
- var xsltTree= new ActiveXObject("Msxml2.DOMDocument.4.0");
- xsltTree.async = false;
- xsltTree.load(xslPath);
-
- return srcTree.transformNode(xsltTree);
- }
-
- //handler for showfilter link
- function OnShowFilter()
- {
- if( document.all.idFilter.className == "clsShow")
- {
- document.all.idFilter.className = "clsHide";
- idFilterLink.innerText = "Enable Filter ";
- }
- else
- {
- document.all.idFilter.className = "clsShow";
- idFilterLink.innerText = "Disable Filter ";
- }
-
- if (idModule.selectedIndex != 0 ||
- idApp.value != "" ||
- idAr.selectedIndex != 0 ||
- idSort.selectedIndex != 0)
-
- Main();
-
- OnResize();
- }
-
- // handler for Module combo link
- function OnChangeModule(cmbModule)
- {
- switch(cmbModule.options[cmbModule.selectedIndex].value)
- {
- case "2":
- idApp.disabled = false;
- idFWFilter.className="clsShow";
- idSBXFilter.className="clsHide";
- break;
- case "16":
- idApp.value="";
- idSelectApp.selectedIndex = 0;
- idApp.disabled = true;
- idFWFilter.className="clsHide";
- idSBXFilter.className="clsShow";
- break;
- case "1":
- idApp.disabled = false;
- idFWFilter.className="clsHide";
- idSBXFilter.className="clsShow";
- break;
- default:
- idApp.disabled = false;
- idFWFilter.className="clsHide";
- idSBXFilter.className="clsHide";
- break;
- }
- }
-
- function OnChangeDisplay()
- {
- for (i = 0; i < 2; i++) if (radio_display[i].checked==true)
- {
- s_iDisplayType = radio_display[i].value;
- break;
- }
- Main();
- return 0;
- }
-
- function OnChangeSort()
- {
- if (idSort.selectedIndex == 1)
- {
- idModule.selectedIndex = 0;
- idModule.disabled = 1;
- idApp.value = "";
- idApp.disabled = 1;
- idSelectApp.disabled = 1;
- idAr.selectedIndex = 0;
- idAr.disabled = 1;
- }
- else
- {
- idModule.disabled = 0;
- idApp.disabled = 0;
- idSelectApp.disabled = 0;
- idAr.disabled = 0;
- }
- Main();
- }
-
- function OnAppSelected()
- {
- var strApp = idSelectApp.value;
- if (strApp != "")
- if (strApp == "*")
- idApp.value = "";
- else
- idApp.value = strApp;
- Main();
- }
-
- function GetComboApps()
- {
- var strRet = new String();
- strRet += '<select id="idSelectApp" name="idSelectApp" onchange="OnAppSelected();">';
- strRet += '<option value=""><or choose here></option>';
- strRet += '<option value="*"><All></option>';
- try
- {
- var arrAppParsers = new Array( window.external.ServerParser(64), window.external.ClientParser(64) );
- var pthExpander = new ActiveXObject("SBXPathExpander.SBXPathExpander.1");
- var i = 0;
- for (i = 0; i < arrAppParsers.length; i++)
- {
- var arrLabels = new Array(), arrPaths = new Array();
- var pLabelList = arrAppParsers[i].LabelList;
- var enLabels = new Enumerator(pLabelList);
- enLabels.moveFirst();
- while (!enLabels.atEnd())
- {
- var pLabel = enLabels.item();
- if (pLabel.Type == LT_PATH || pLabel.Type == LT_CHECKSUM_AND_PATH)
- {
- var arrExp = pthExpander.ExpandFilePath2(pLabel.Path).toArray();
- if (arrExp.length > 0)
- {
- var strLabel = new String(pLabel.LabelID);
- arrLabels[arrLabels.length] = strLabel;
- arrPaths[strLabel] = arrExp[0];
- }
- }
- enLabels.moveNext();
- }
- arrLabels.sort();
- var j = 0, n = arrLabels.length;
- for (j = 0; j < n; j++)
- {
- var strLabel = new String(arrLabels[j]);
- strRet += '<option value="' + arrPaths[strLabel] + '">' + strLabel + '</option>';
- }
- }
- }
- catch (e)
- {
- }
- strRet += '</select>';
- return strRet;
- }
-
-
- window.onresize=OnResize;
-
-
- function OnResize()
- {
- iSize=0;
- if (IsIE6())
- {
- var oParentFrame = window.frameElement;
- iSize=oParentFrame.offsetHeight - document.all.idResult.offsetTop ;
- }
- else
- {
- iSize=document.body.clientHeight - document.all.idResult.offsetTop - 32 ;
- }
- if(iSize<100) iSize=100;
- document.all.idResult.style.height=iSize;
- }
-